<?php
/**
 * Created by PhpStorm.
 * User: 任崇斌
 * Date: 2016/8/24
 * Time: 下午 3:13
 */
namespace Company\Controller;

use Think\Controller;

class NewsTypeController extends Controller
{

    public function getNewsT()
    {
        //  获取数据库新闻信息
        $newsT=D("news_t");
        $list=$newsT->select();
        $this->assign("list",$list);
        $this->display();
    }

    public function addNewsT(){
        //添加新闻
        $title=$_POST["title"];
        $d=D("news_t");
        $data["title"]=$title;
        $data["sid"]=1;
        $re=$d->add($data);
        if(!empty($re)){
            $this->success('添加成功','getNewsT');
        }
        else{
            $this->error('添加失败','getNewsT');
        }

    }

    public function upNewsT(){
        //根据id获取表单数据库信息
        $id=$_GET["id"];
        $d=D("news_t");
        $list=$d->where("id='$id'")->select();
        $this->assign("list",$list);
        $this->display();

    }

    public function  edNewsT(){
        //  跟新新闻数据库操作
        $id=$_POST["id"];
        $title=$_POST["title"];
        $d=D("news_t");
        $data["title"]=$title;
        $data["sid"]=1;
        $re=$d->where("id='$id'")->save($data);
        if(!empty($re)){
            $this->success('更改成功','getNewsT');
        }
        else{
            $this->error('更改失败','getNewsT');
        }
    }

    public function delete(){
        //  删除新闻类操作
        $id=$_GET["id"];
        $delete=D("news_t");
        $de = $delete->delete($id);
        if(!empty($de)){
            $this->success('删除成功','/newsType/getNewsT');
        }
        else{
            $this->error('删除失败','/newsType/getNewsT');
        }

    }

}